package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.MesSaleExpressDetail;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.MesSaleExpressDetailDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2022-07-25 14:54:21
 */
public class MesSaleExpressDetailConverts {

    private static Logger LOG = LoggerFactory.getLogger(MesSaleExpressDetailConverts.class);

    public static List<MesSaleExpressDetailDTO> convert(List<MesSaleExpressDetail> mesSaleExpressDetailList) {
        if (CollectionUtils.isEmpty(mesSaleExpressDetailList)) {
            return Collections.EMPTY_LIST;
        }

        List<MesSaleExpressDetailDTO> mesSaleExpressDetailListResult = Lists.newArrayList();
        for (MesSaleExpressDetail mesSaleExpressDetail : mesSaleExpressDetailList) {
            mesSaleExpressDetailListResult.add(convert(mesSaleExpressDetail));
        }
        return mesSaleExpressDetailListResult;
    }

    public static MesSaleExpressDetailDTO convert(MesSaleExpressDetail mesSaleExpressDetail) {
        try {
            return BeanUtils.copy(mesSaleExpressDetail, MesSaleExpressDetailDTO.class);
        } catch (Exception e) {
            LOG.error("MesSaleExpressDetail到MesSaleExpressDetailDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "MesSaleExpressDetail到MesSaleExpressDetailDTO转换失败", e);
        }
    }

    public static MesSaleExpressDetail convert(MesSaleExpressDetailDTO mesSaleExpressDetailDTO) {
        try {
            return BeanUtils.copy(mesSaleExpressDetailDTO, MesSaleExpressDetail.class);
        } catch (Exception e) {
            LOG.error("MesSaleExpressDetailDTO到MesSaleExpressDetail转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "MesSaleExpressDetailDTO到MesSaleExpressDetail转换失败", e);
        }
    }
}